
import com.one.net.FailListener;
import com.one.net.SuccessListener;
import org.omg.CosNaming.BindingIterator;
import sun.plugin2.os.windows.FLASHWINFO;

import javax.imageio.ImageIO;
import javax.print.attribute.Size2DSyntax;
import javax.security.auth.login.CredentialException;
import javax.security.auth.login.FailedLoginException;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;

public class TestRouteSystem {

    JFrame jf=new JFrame("公交路线查询系统");
    //final int WIDTH=600;
   // final int HEIGHT=500;
    public  void init(){
        //设置窗口相关的属性
        jf.setBounds(500,500,450,250);
        jf.setLocationRelativeTo(null);
        jf.setResizable(false);
        // new BackGroundPanel(ImageIO.read)
        //登录相关的元素
        Box vBox=Box.createVerticalBox();
        //组装用户名
        Box uBox=Box.createHorizontalBox();
        JLabel uLabel=new JLabel("用户名:");
        JTextField uField=new JTextField(33);
        uBox.add(uLabel);
        uBox.add(Box.createHorizontalStrut(10));
        uBox.add(uField);
        //组装密码
        Box pBox=Box.createHorizontalBox();
        JLabel pLabel=new JLabel("密    码:");
        JTextField pField=new JTextField(33);
        pBox.add(pLabel);
        pBox.add(Box.createHorizontalStrut(10));
        pBox.add(pField);
        //组装按钮
        Box btnBox=Box.createHorizontalBox();
        JButton loginBtn=new JButton("登录");
        JButton registBtn=new JButton("注册");
        loginBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String username=uField.getText().trim();
                String passsword=pField.getText().trim();
                Map<String,String> params=new HashMap<>();
                params.put("username",username);
                params.put("password",passsword);
                com.one.net.PostUtils.postWithParams("http://localhost:8080/user/login", params, new SuccessListener() {
                    @Override
                    public void success(String result) {

                    }
                }, new FailListener() {
                    @Override
                    public void fail() {
                        JOptionPane.showMessageDialog(jf,"网络异常");
                    }
                });


            }
        });
        btnBox.add(loginBtn);
        btnBox.add(Box.createHorizontalStrut(250));
        btnBox.add(registBtn);

        vBox.add(Box.createVerticalStrut(50));
        vBox.add(uBox);
        vBox.add(Box.createVerticalStrut(40));
        vBox.add(pBox);
        vBox.add(Box.createVerticalStrut(40));
        vBox.add(btnBox);
        jf.add(vBox);



        jf.setVisible(true);

    }
    public static void main(String[] args) {
        try{
            Class.forName("com.mysql.jdbc.Driver");
            System.out.println("加载成功");
        }catch(ClassNotFoundException e){
            e.printStackTrace();
        }
        



     /* new TestRouteSystem().init();

        Route route1 = new SpecificRoute("Route 1", new ArrayList<>(Arrays.asList("S1", "S2", "S3",
                "S4", "S5")),"S1", "S5");
        Route route2 = new SpecificRoute("Route 2", new ArrayList<>(Arrays.asList("S2","S3",
                "S4", "S5","S6")),"S1", "S6");
        route1.addStation("S6");
        route1.removeStation("S2");
        route1.updateStation("S3", "S7");

        System.out.println("请输入要查询的站点：");
        Scanner scanner=new Scanner(System.in);
        String s=scanner.nextLine();
        ArrayList<Route> routes=new ArrayList<>();
        routes.add(route1);
        routes.add(route2);
        for (Route r : routes) {
            r.queryStations(s);

        }*/
    }


}